/**
* 系统初始化时回调，可以注入三方脚本
* @param {*} vue Vue实例
* @param {*} type 有个参数值 desktop / mobile
* @returns Promise / void
*/
window.BaitedaInit = async function(vue, type) {
  return new Promise(function (resolve, reject) {    
    // 增加多个组件的引用
    const echarts = document.createElement('script')
    echarts.src = 'https://fe-resource.baiteda.com/libs/echarts-5.3.2/echarts.min.js'
    echarts.crossorigin = 'true'
    echarts.onerror = function() {reject()}
    echarts.onload = function() {
      // 已经获取到 window.echarts，此处可以做一些全局设置
      resolve(true)
    }
    document.body.appendChild(echarts)
    // 结束
  })
}

/**
* 用户身份认证时回调，仅在私有化环境中启用
* @param {*} user 用户对象
* @param {*} tenant 租户对象
*/
window.BaitedaLogin = function(user, tenant) {}

/**
* 页面全局路由变更时回调，仅在私有化环境中启用
* @param {*} to 目标页面
* @param {*} from 当前页面
*/
window.BaitedaRouterChanged = function(to, from) {}

/**
 * 平台关闭页面的行为干预
 * @param params {
 *   type: "desktop" | "mobile";
 *   browserType: string;
 *   taskRedirectUrl: string;
 *   appLauncher: boolean;
 * }
 */
window.BaitedaClose = function(params) {}

/**
 * 全局注入请求头额外参数
 * @param {*} headers 请求头信息
 * @returns 返回的对象就会被注入到请求头部
 */
window.BaitedaRequestHeaders = function(headers) {return headers}

/**
 * 创建单据、浏览页面、编辑页面，以iframe形式打开，会通过此函数获取到url，进行预处理。如：qiankun等微前端地址替换的处理
 * @param url 
 * @param method: 'create' | 'edit' | 'read'
 * @returns url地址
 */
window.BaitedaGetIframeUrl = function(url, method) {return url}

//4.0.0版本提供
window.baitedaCustomFileSupportOnlineView = function(file, type, device) {
  /**
  file: {
    "tenant_id": "testqw",
    "file_id": "b1c72447c9c44c58ba42a5aad4b6b3ae",
    "file_name": "base64.min.js",
    "file_path": "/attach/attachment/testqw/20230521/b1c72447c9c44c58ba42a5aad4b6b3ae/base64.min.js",
    "file_size": 5094,
    "create_time": 1684681790996,
    "support_online_view": false,
    "online_view_url": null,
    "download_url": "//testqw.baiteda.com/attachment/api/v1/private/download/b1c72447c9c44c58ba42a5aad4b6b3ae",
    "del_file_url": "//testqw.baiteda.com/attachment/api/v1/private/del?fileId=b1c72447c9c44c58ba42a5aad4b6b3ae"
  },
  type: 'isSupport' | 'getUrl'
  device: 'desktop' | 'mobile'
  */
  if (type === 'isSupport') {return false}
  else if (type === 'getUrl') {return ''}
}